package com.bwie.home.backstage.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bwie.home.backstage.entity.vo.UserIdAndHousesId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bwie.home.backstage.entity.HousesUserReplyEntity;
import com.bwie.home.backstage.service.HousesUserReplyService;
import com.bwie.home.common.utils.PageUtils;
import com.bwie.home.common.utils.R;



/**
 * 
 *
 * @author sy
 * @email sunlightcs@gmail.com
 * @date 2021-09-10 09:46:41
 */
@RestController
@RequestMapping("backstage/housesuserreply")
public class HousesUserReplyController {
    @Autowired
    private HousesUserReplyService housesUserReplyService;


    @RequestMapping("/UserIdAndHousesId")
    public R UserIdAndHousesId(@RequestBody UserIdAndHousesId userIdAndHousesId){
        List<HousesUserReplyEntity> list = housesUserReplyService.list(new QueryWrapper
                <HousesUserReplyEntity>().eq("user_id", userIdAndHousesId.getUserId()).eq("houses_id", userIdAndHousesId.getHousesId()));


        return R.ok().put("list", list);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = housesUserReplyService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{replyId}")
    public R info(@PathVariable("replyId") Integer replyId){
		HousesUserReplyEntity housesUserReply = housesUserReplyService.getById(replyId);

        return R.ok().put("housesUserReply", housesUserReply);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody HousesUserReplyEntity housesUserReply){
		housesUserReplyService.save(housesUserReply);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody HousesUserReplyEntity housesUserReply){
		housesUserReplyService.updateById(housesUserReply);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] replyIds){
		housesUserReplyService.removeByIds(Arrays.asList(replyIds));

        return R.ok();
    }

}
